/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package regulatoryInteractionsStats.yeast;

import functionalEnrichment.semanticSimilarity.semanticSimilarityCalculator.utils.FileUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;

/**
 *
 * @author jamie
 */
public class PPIInteractionSet {

    private HashSet<String> ppiInteractions = new HashSet<String>();
    private HashSet<String> genes = new HashSet<String>();
    private File ppiInteractionsFile = new File("/Users/jamie/Dropbox/monkeys/yeast/ppiInteractions.txt");
    private YeastGeneLibrary yeastGeneLibrary;


    public PPIInteractionSet(YeastGeneLibrary yeastGeneLibrary) {
        this.yeastGeneLibrary = yeastGeneLibrary;
        populateInteractions();
    }

    public void populateInteractions(){
        BufferedReader reader = FileUtils.getBufferedReader(ppiInteractionsFile);
        String line;
        try {
            while ((line = reader.readLine()) != null) {
                String[] split = line.split("\t");
                YeastGene yg1 = yeastGeneLibrary.getGeneByAccession(split[0]);
                YeastGene yg2 = yeastGeneLibrary.getGeneByAccession(split[2]);
                if(yg1!=null && yg2!=null){
                    String[] symbols = new String[2];
                    symbols[0] = yg1.getSymbol();
                    symbols[1] = yg2.getSymbol();
                    Arrays.sort(symbols);
                    ppiInteractions.add(symbols[0]+":"+symbols[1]);
                    if(!genes.contains(symbols[0])){
                        genes.add(symbols[0]);
                    }
                    if(!genes.contains(symbols[1])){
                        genes.add(symbols[1]);
                    }
                }
            }
            reader.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public HashSet<String> getPPIInteractions() {
        return ppiInteractions;
    }

    public YeastGeneLibrary getYeastGeneLibrary() {
        return yeastGeneLibrary;
    }

    public HashSet<String> getGenes() {
        return genes;
    }

    

}
